package com.tfswue.jqr.service;

import com.tfswue.jqr.apis.BookClient;
import com.tfswue.jqr.entity.Book;
import com.tfswue.jqr.entity.Borrow;
import com.tfswue.jqr.mapper.BorrowMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.Date;

@Service
public class BorrowService {

    @Autowired
    private BorrowMapper borrowMapper;

    @Autowired
    private BookClient bookClient;

    //负载
    public String borrowBook(Long userId, Long bookId) {
        Book book = bookClient.getBookById(bookId);
        if (book == null) {
            return "图书不存在，借阅失败";
        }
        Borrow borrow = new Borrow();
        borrow.setUserId(userId);
        borrow.setBookId(bookId);
        borrow.setBorrowDate(new Date());
        borrowMapper.insert(borrow);
        return "借阅成功";
    }
}
